#ifndef __EV_SATELLITE_CL_DATA_H__
#define __EV_SATELLITE_CL_DATA_H__


#include<stdint.h>
#include<string>
#include<vector>
#include"TimePoint.hpp"
#include"rapidjson/document.h"

namespace SC_SUN
{

struct EvSatelliteCLData
{

//////基本信息//////
/*
长度：5位
范围：1- SAT_NUM
格式：SAT+XXXXX
【SAT0000*】
【SAT000**】
【SAT00***】
【SAT0****】
【SAT*****】
*/
std::string SAT_SN;                                     ///< 卫星创建序号

//////星钟信息//////
std::vector<double> SAT_JD_HF;                          ///< 高精度儒略日序列,单位：天
std::vector<double> SAT_ST_HF;                          ///< 高精度仿真时序列,单位：秒
std::vector<double> SAT_JD_MS;                          ///< 带误差的儒略日星钟序列,单位：天
std::vector<double> SAT_ST_MS;                          ///< 带误差的仿真时星钟序列,单位：秒
std::vector<double> SAT_ST_ER;                          ///< 星钟仿真时误差序列,单位：纳秒
std::vector<double> SAT_ER_DR;                                       ///< 钟差漂移率,单位：纳秒/天


auto ObjToJsonObject(rapidjson::Document& doc)
{
    using namespace rapidjson;
  
    Value obj(kObjectType);

    doc.AddMember(Value("SAT_SN", doc.GetAllocator()), Value(SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());

    Value value5(kArrayType);
    for (int i = 0; i < SAT_JD_HF.size(); i++)
    {
        value5.PushBack(SAT_JD_HF[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_JD_HF", doc.GetAllocator()), value5, doc.GetAllocator());

    Value value6(kArrayType);
    for (int i = 0; i < SAT_ST_HF.size(); i++)
    {
        value6.PushBack(SAT_ST_HF[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_ST_HF", doc.GetAllocator()), value6, doc.GetAllocator());

    Value value7(kArrayType);
    for (int i = 0; i < SAT_JD_MS.size(); i++)
    {
        value7.PushBack(SAT_JD_MS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_JD_MS", doc.GetAllocator()), value7, doc.GetAllocator());

    Value value8(kArrayType);
    for (int i = 0; i < SAT_ST_MS.size(); i++)
    {
        value8.PushBack(SAT_ST_MS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_ST_MS", doc.GetAllocator()), value8, doc.GetAllocator());


    Value value9(kArrayType);
    for (int i = 0; i < SAT_ST_ER.size(); i++)
    {
        value9.PushBack(SAT_ST_ER[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_ST_ER", doc.GetAllocator()), value9, doc.GetAllocator());

    //obj.AddMember(Value("SAT_ER_DR", doc.GetAllocator()), Value(SAT_ER_DR), doc.GetAllocator());
    Value value10(kArrayType);
    for (int i = 0; i < SAT_ER_DR.size(); i++)
    {
        value10.PushBack(SAT_ER_DR[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_ER_DR", doc.GetAllocator()), value10, doc.GetAllocator());

    return obj;
}

static EvSatelliteCLData JsonObjectToObject(rapidjson::GenericObject<true, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteCLData ret;

    //auto obj = doc.GetObj();
    ret.SAT_SN = obj["SAT_SN"].GetString();

    auto array5 = obj["SAT_JD_HF"].GetArray();
    for (int i = 0; i < array5.Size(); i++)
    {
        ret.SAT_JD_HF.push_back(array5[i].GetDouble());
    }

    auto array6 = obj["SAT_ST_HF"].GetArray();
    for (int i = 0; i < array6.Size(); i++)
    {
        ret.SAT_ST_HF.push_back(array6[i].GetDouble());
    }

    auto value7 = obj["SAT_JD_MS"].GetArray();
    for (int i = 0; i < value7.Size(); i++)
    {
        ret.SAT_JD_MS.push_back(value7[i].GetDouble());
    }

    auto value8 = obj["SAT_ST_MS"].GetArray();
    for (int i = 0; i < value8.Size(); i++)
    {
        ret.SAT_ST_MS.push_back(value8[i].GetDouble());
    }

    auto value9 = obj["SAT_ST_ER"].GetArray();
    for (int i = 0; i < value9.Size(); i++)
    {
        ret.SAT_ST_ER.push_back(value9[i].GetDouble());
    }
    //ret.SAT_ER_DR = obj["SAT_ER_DR"].GetDouble();
    auto value10 = obj["SAT_ER_DR"].GetArray();
    for (int i = 0; i < value10.Size(); i++)
    {
        ret.SAT_ST_ER.push_back(value10[i].GetDouble());
    }

    return ret;
}


static EvSatelliteCLData JsonObjectToObject2(rapidjson::GenericObject<false, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteCLData ret;

    //auto obj = doc.GetObj();
    ret.SAT_SN = obj["SAT_SN"].GetString();

    auto array5 = obj["SAT_JD_HF"].GetArray();
    for (int i = 0; i < array5.Size(); i++)
    {
        ret.SAT_JD_HF.push_back(array5[i].GetDouble());
    }

    auto array6 = obj["SAT_ST_HF"].GetArray();
    for (int i = 0; i < array6.Size(); i++)
    {
        ret.SAT_ST_HF.push_back(array6[i].GetDouble());
    }

    auto value7 = obj["SAT_JD_MS"].GetArray();
    for (int i = 0; i < value7.Size(); i++)
    {
        ret.SAT_JD_MS.push_back(value7[i].GetDouble());
    }

    auto value8 = obj["SAT_ST_MS"].GetArray();
    for (int i = 0; i < value8.Size(); i++)
    {
        ret.SAT_ST_MS.push_back(value8[i].GetDouble());
    }

    auto value9 = obj["SAT_ST_ER"].GetArray();
    for (int i = 0; i < value9.Size(); i++)
    {
        ret.SAT_ST_ER.push_back(value9[i].GetDouble());
    }
    //ret.SAT_ER_DR = obj["SAT_ER_DR"].GetDouble();
    auto value10 = obj["SAT_ER_DR"].GetArray();
    for (int i = 0; i < value10.Size(); i++)
    {
        ret.SAT_ST_ER.push_back(value10[i].GetDouble());
    }

    return ret;
}


};


}


#endif
